<template>
  <div>
    <footer class="footer">
      <span class="todo-count"
        >剩余<strong>{{ leftCount }}</strong></span
      >
      <ul class="filters" @click="$emit('changeType',type)">
        <!-- 人为定义三个状态 全部为all 进行中为active 已完成completed -->
        <li>
          <a
            :class="{ selected: type === 'all' }"
            @click.prevent="type = 'all'"
            href="#/"
            >全部</a
          >
        </li>
        <li>
          <a
            :class="{ selected: type === 'active' }"
            @click.prevent="type = 'active'"
            href="#/active"
            >进行中</a
          >
        </li>
        <li>
          <a
            :class="{ selected: type === 'completed' }"
            @click.prevent="type = 'completed'"
            href="#/completed"
            >已完成</a
          >
        </li>
      </ul>
      <button v-show="showClear" @click="hClear" class="clear-completed">
        清除已完成
      </button>
    </footer>
  </div>
</template>

<script>
export default {
  name: "VueDemoTodoFooter",
  props: {
    list: {
      required: true,
      type: Array,
    },
  },
  data() {
    return {
      type:'all'
    };
  },
  computed: {
    leftCount() {
      return this.list.length;
    },
    //显示隐藏，如果isDone是true,就显示，如果isDone都是false就隐藏
    showClear() {
      return this.list.some((item) => item.isDone);
    },
  },
  methods: {
    hClear() {
      //给清除已完成绑定点击事件,将数据传到父组件中让父组件进行筛选
      this.$emit("clearDone");
    },
  },
};
</script>

<style lang="scss" scoped>
</style>